package message.receive;

import io.netty.buffer.ByteBuf;
import message.Receive;
import message.ReceiveType;
import util.Constants;

public class JoinGroupReceive implements Receive
{
    private byte   code;
    private String codeMsg;

    public byte getCode()
    {
        return code;
    }

    public void setCode(byte code)
    {
        this.code = code;
    }

    public String getCodeMsg()
    {
        return codeMsg;
    }

    public void setCodeMsg(String codeMsg)
    {
        this.codeMsg = codeMsg;
    }

    @Override
    public ReceiveType type()
    {
        return ReceiveType.JOIN_GROUP;
    }

    @Override
    public void writeToMessage(ByteBuf buf)
    {
        buf.writeByte(5);
        buf.writeByte(code);
        byte[] msgBytes = codeMsg.getBytes(Constants.CHARSET);
        buf.writeInt(msgBytes.length);
        buf.writeBytes(msgBytes);
    }
}
